﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nancy;
using Nancy.ModelBinding;
using YAPSAR.Database;
using YAPSAR.Domain;

namespace YAPSAR.Web.Index
{
    public class IndexModule : Nancy.NancyModule
    {
        public IndexModule()
        {
#if DEBUG
            StaticConfiguration.Caching.EnableRuntimeViewDiscovery = true;
            StaticConfiguration.Caching.EnableRuntimeViewUpdates = true;
#endif

            Get["/"] = Index;
        }

        private dynamic Index(dynamic parameters)
        {
            //this.ViewBag.title = "Yeah!";

            var binding = this.Bind<IndexModel>();
            if (binding == null)
            {
                binding = new IndexModel();
            }

            using (var tx = DatabaseManager.Instance.Session.BeginTransaction())
            {
                var criteria = DatabaseManager.Instance.Session.CreateCriteria<Process>();
                binding.Processes = criteria.Future<Process>();

                tx.Commit();
            }

            //this.model.Value = binding.Value;

            return View["Index", binding];
        }
    }
}
